<?php

class ModuleDAO {
    
    public static function getInfo($mid) {
        if($mid < 1) {
            return array();
        }
        $db = Database::getInstance();
        $db->query("SELECT * FROM modules WHERE mid=" . $mid);
        if($db->getNumRows() > 0) {
            return $db->dbToObjectKeys($db->getRowAssoc());
        }
        else {
            return array();
        }
    }
    
    public static function getAllowedUsers($mid) {
        $db = Database::getInstance();
        $db->query("
                    SELECT
                        u.uid
                    FROM
                            users u
                        JOIN
                            user_rights ur
                        ON(u.uid = ur.uid)
                    WHERE
                        ur.mid = $mid AND
                        ur.lvl > 0
                    UNION
                    SELECT
                        u.uid
                    FROM
                            users u
                        JOIN
                            group_rights gr
                        ON(gr.gid = u.gid)
                    WHERE
                        gr.mid = $mid AND
                        gr.lvl > 0
                    ");
        return $db->getField('uid');
    }
    
    
}

?>
